﻿namespace Homework04
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //input a binary number
            Console.Write("请输入一个二进制数: ");
            string? userInput = Console.ReadLine();

            //initialize the decimal number
            int decimalNumber = 0;

            for (int i = 0; i < userInput.Length; i++)
            {
                //obtain the current character
                char bit = userInput[userInput.Length - 1 - i];

                //judge whether the current character is "1"
                if (bit == '1')
                {
                    decimalNumber += (int)Math.Pow(2, i);
                }
            }
            Console.WriteLine("二进制数的十进制形式是："+decimalNumber);
        }
    }
}
